import {Component, OnInit} from '@angular/core';
import {
  AbstractControl,
  FormBuilder,
  FormGroup,
  Validators
} from '@angular/forms';
import { Router } from '@angular/router';

@Component({
  selector: 'app-login',
  templateUrl: './login.component.html',
  styleUrls: ['./login.component.css']
})
export class LoginComponent implements OnInit {
  validateForm: FormGroup;
  userName: String;
  password: String;

  submitForm(): void {
    let control: AbstractControl;
    for (const i in this.validateForm.controls) {
      control = this.validateForm.controls[i];
      control.markAsDirty();
      control.updateValueAndValidity();
      console.log(control);
    }
    console.log(`username:${this.userName},password:${this.password}`);
    if ('kedong' === this.userName && '123456' === this.password) {
        this.router.navigate(['/index']);
    }
  }

  constructor(private fb: FormBuilder,
    private router: Router) {
  }

  ngOnInit() {
    this.validateForm = this.fb.group({
      userName: [null, [Validators.required]],
      password: [null, [Validators.required]],
      remember: [true]
    });
  }

}
